<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>表格隔行变色</title>
    <style>
      table {
        width: 700px;
        margin: 100px auto;
        text-align: center;
        font-size: 14px;
        border-collapse: collapse;
      }

      thead > tr {
        height: 30px;
        background-color: #7ec9ec;
      }

      tbody > tr {
        height: 30px;
        color: #5968d1;
        border-bottom: 1px solid #ebedea;
        cursor: pointer;
      }

      .bg {
        background-color: #e5f2f8;
      }
    </style>
  </head>
  <body>
    <table>
      <thead>
        <tr>
          <th>代码</th>
          <th>名称</th>
          <th>最新公布净值</th>
          <th>累计净值</th>
          <th>前单位净值</th>
          <th>净值增长率</th>
        </tr>
      </thead>

      <tbody>
        <tr>
          <td>600519</td>
          <td>贵州茅台</td>
          <td>1.075</td>
          <td>1.079</td>
          <td>1.074</td>
          <td>+0.047%</td>
        </tr>
        <tr>
          <td>000799</td>
          <td>酒鬼酒</td>
          <td>1.026</td>
          <td>1.037</td>
          <td>1.045</td>
          <td>+0.024%</td>
        </tr>
        <tr>
          <td>000858</td>
          <td>五粮液</td>
          <td>1.061</td>
          <td>1.050</td>
          <td>1.038</td>
          <td>+0.037%</td>
        </tr>
        <tr>
          <td>600600</td>
          <td>青岛啤酒</td>
          <td>1.089</td>
          <td>1.074</td>
          <td>1.069</td>
          <td>+0.086%</td>
        </tr>
        <tr>
          <td>002461</td>
          <td>珠江啤酒</td>
          <td>1.055</td>
          <td>1.037</td>
          <td>1.044</td>
          <td>+0.061%</td>
        </tr>
        <tr>
          <td>300015</td>
          <td>爱尔眼科</td>
          <td>1.073</td>
          <td>1.065</td>
          <td>1.082</td>
          <td>+0.087%</td>
        </tr>
      </tbody>
    </table>

    <script>
      var rows = document.querySelector('tbody').querySelectorAll('tr');

      for (var i = 0; i < rows.length; i++) {
        // 鼠标移入
        rows[i].onmouseover = function () {
          this.className = 'bg';
        };

        // 鼠标移出
        rows[i].onmouseout = function () {
          this.className = '';
        };
      }
    </script>
  </body>
</html>
